<link rel="stylesheet" href="https://unpkg.com/layui@2.6.8/dist/css/layui.css">
<style>
    .layui-form-label {
        width: 50px;
        padding: 9px 5px 9px 0;
    }
</style>
<div class="layui-panel" style="margin: 10px 0;padding: 10px 0 0 0;">
    <form action="{$_SERVER['REQUEST_URI']}" class="layui-form" method="POST">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">用戶ID</label>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="uid" autocomplete="off" class="layui-input" value="{$_REQUEST['uid']}" />
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">用戶名</label>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="username" autocomplete="off" class="layui-input" value="{$_REQUEST['username']}" />
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">訂單號</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <input type="text" name="order_id" autocomplete="off" class="layui-input" value="{$_REQUEST['order_id']}" />
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">狀態</label>
                <div class="layui-input-inline" style="width: 100px;">
                    <select name="status">
                        <option value="" <!--{if $_REQUEST['status']==''}-->selected<!--{/if}-->>全部狀態</option>
                        <option value="reject" <!--{if $_REQUEST['status']=='reject'}-->selected<!--{/if}-->>退回</option>
                        <option value="wait" <!--{if $_REQUEST['status']=='wait'}-->selected<!--{/if}-->>等待</option>
                        <option value="payed" <!--{if $_REQUEST['status']=='payed'}-->selected<!--{/if}-->>已支付</option>
                        <option value="complete" <!--{if $_REQUEST['status']=='complete'}-->selected<!--{/if}-->>已完成</option>
                    </select>
                </div>
            </div>

            <div class="layui-inline">
                <div class="layui-input-inline" style="width: 100px;">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">查詢</button>
                </div>
            </div>

        </div>
    </form>
</div>
<table class="tb tb2 ">
    <thead>
        <tr>
            <th colspan="15" class="partition">信息列表</th>
        </tr>
        <tr class="header">
            <th>訂單號/二維碼</th>
            <th>提現時間</th>
            <th>用戶名</th>
            <th>提現數量</th>
            <th>EAC</th>
            <th>提現地址</th>
            <th>狀態</th>
        </tr>
    </thead>
    <tbody id="list_body">
        <!--{loop $datalist $key $value}-->
        <tr>
            <td>
                <a href="javascript:;" data-href="/plugin.php?id=cc_cansnow_eacpay:eacpay_admin&action=qrcode&amount={$value['amount']}&orderid={$value['order_id']}&address={$value['address']}" class="orderid">
                    <!--{$value['order_id']}-->
                </a>
            </td>
            <td>
                <!--{date($value['create_time'],'Y-m-d H:i:s')}-->
            </td>
            <td>
                <!--{$value['username']}-->
            </td>
            <td>
                <!--{$value['amount']}-->
            </td>
            <td>
                <!--{$value['eac']}-->
            </td>
            <td>
                <!--{$value['address']}-->
            </td>
            <td>
                <!--{if $value['status'] == 'wait' }-->
                <a href="javascript:;" class="statusSelect<!--{$value['status']}-->" data-status="<!--{$value['status']}-->" data-orderid="<!--{$value['order_id']}-->">
                    等待處理
                </a>
                <!--{elseif $value['status'] == 'reject' }-->
                已退回
                <!--{else}-->
                完成
                <!--{/if}-->
            </td>
        </tr>
        <!--{/loop}-->
    </tbody>
</table>
<div id="pagenation"></div>
<script id="optinTpl" type="text/html">
    <label><input type="radio" name="statusSelect" value="reject" {{#  if(d.status == 'reject'){ }}checked{{#  } }}>拒絕</label>
    <label><input type="radio" name="statusSelect" value="wait" {{#  if(d.status == 'wait'){ }}checked{{#  } }}>等待支付</label>
    <label><input type="radio" name="statusSelect" value="complete" {{#  if(d.status == 'complete'){ }}checked{{#  } }} >支付完成</label>
</script>
<script src="https://unpkg.com/layui@2.6.8/dist/layui.js"></script>
<script>
    var $ = layui.jquery;
    $('.statusSelectwait').on('click', function() {
        var that = $(this);
        var s = $(this).data('status');
        var order_id = $(this).data('orderid');
        layui.layer.open({
            title: '改變訂單狀態',
            content: layui.laytpl($('#optinTpl').html()).render({
                status: s
            }),
            yes: function(index, layero) {
                var checked = layero.find('input[name=statusSelect]:checked').val();
                $.post('plugin.php?id=cc_cansnow_eacpay:eacpay_admin&action=changestatus',{
                    status: checked,
                    order_id: order_id,
                },
                function(d) {
                    if (d == 'ok') {
                        that.data('status', checked);
                        layui.layer.msg("操作成功", {
                            icon: 1,
                            time: 2000
                        },function(){
                            window.location.reload();
                        });
                    } else {

                    }
                });
            }
        });
    });
    $('.orderid').on('mouseenter', function() {
        layui.layer.tips('<img src="' + $(this).data('href') + '" />', this);
    });

    layui.laypage.render({
        elem: 'pagenation',
        count: '{$totalCount}',
        limit: '{$pagesize}',
        curr: '{$page}',
        jump: function(obj, first) {
            //obj包含了當前分頁的所有參數，比如：
            console.log(obj.curr); //得到當前頁，以便向服務端請求對應頁的數據。
            console.log(obj.limit); //得到每頁顯示的條數

            //首次不執行
            if (!first) {
                var url = window.location.href;
                url = url.replace(/&page=\d+/, '');
                url += "&page=" + obj.curr;
                window.location.href = url;
            }
        }
    });
</script>